How can I correctly iterate through a String array without causing an Array Index Out of Bounds exce